//
//  MHomeViewController.m
//  Mask
//
//  Created by 郭子一 on 2020/10/2.
//  Copyright © 2020 郭子一. All rights reserved.
//

#import "MHomeViewController.h"
#import "MSettingViewController.h"
#import "MDeviceSwitchingViewController.h"
#import "MNotificationViewController.h"
@interface MHomeViewController ()
@property (nonatomic, strong) UILabel *deviceLabel; // 设备名称
@property (nonatomic, strong) UIImageView *deviceImage; // 设备图片
@property (nonatomic, strong) UILabel *deviceStateLabel; // 设备状态名称
@property (nonatomic, strong) UIButton *switchDeviceStateButton; // 设备状态名称
@property (nonatomic, strong) UIImageView *weatherImage; // 天气图片
@property (nonatomic, strong) UILabel *weatherLabel; // 天气状况
@property (nonatomic, strong) UIView *progressView; // 滤棉消耗
@property (nonatomic, strong) UILabel *spareTimeLabel; // 滤棉剩余时间
@end

@implementation MHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self makeUI];
}

- (void)makeUI
{
    UIScrollView *bgScrollview = [[UIScrollView alloc] init];
//    bgScrollview.frame = CGRectMake(0, 0, kGScreenWidth, kGScreenHeight);
    bgScrollview.showsVerticalScrollIndicator = NO;
//    bgScrollview.backgroundColor = UIColor.cyanColor;
//    bgScrollview.contentSize = CGSizeMake(kGScreenWidth, 812);
    [self.view addSubview:bgScrollview];
    [bgScrollview mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.and.right.equalTo(self.view);
        make.width.mas_equalTo(kGScreenWidth);
        make.top.equalTo(self.view);
        make.height.mas_equalTo(kGScreenHeight);
        // 注意点2：
    //    make.bottom.equalTo(udpateView.mas_bottom).offset(62);
    }];
    
    if (@available(iOS 11.0, *)) {
        bgScrollview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    UIView *headerBgView = [[UIView alloc] init];
    headerBgView.frame = CGRectMake(0, 0, 0, 300);
    [bgScrollview addSubview:headerBgView];
    [headerBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgScrollview.mas_top);
        // 注意点1：
        make.left.and.right.equalTo(self.view);
        make.height.mas_equalTo(300);
    }];
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.colors = @[(__bridge id)RGB_VALUE(0x0191FE).CGColor, (__bridge id)RGB_VALUE(0x00C3FE).CGColor, (__bridge id)RGB_VALUE(0xFFFFFF).CGColor];
    //       gradientLayer.locations = @[@0.3, @5.5, @10.0];
    gradientLayer.startPoint = CGPointMake(0, 0);
    gradientLayer.endPoint = CGPointMake(0, 1);
    gradientLayer.frame = CGRectMake(0, 0, kGScreenWidth, 300);
    [headerBgView.layer addSublayer:gradientLayer];

    self.deviceLabel = [UILabel new];
    self.deviceLabel.text = @"我的口罩设备1";
    self.deviceLabel.font = JSS_FONT_6;
    self.deviceLabel.textAlignment = NSTextAlignmentCenter;
    self.deviceLabel.textColor = RGB_VALUE(0xFFFFFF);
    [headerBgView addSubview:self.deviceLabel];
    [self.deviceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(95);
        make.top.offset(64);
        make.right.offset(-105);
        make.height.mas_equalTo(22);
    }];

    UIButton *settingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [settingBtn addTarget:self action:@selector(settingBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
    [settingBtn setBackgroundImage:[UIImage imageNamed:@"setting"] forState:(UIControlStateNormal)];
    [headerBgView addSubview:settingBtn];
    [settingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.deviceLabel);
        make.left.equalTo(self.deviceLabel.mas_right).offset(5);
        make.width.height.mas_equalTo(40);
    }];

    UIButton *notiBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [notiBtn addTarget:self action:@selector(notiBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
    [notiBtn setBackgroundImage:[UIImage imageNamed:@"homeNotification"] forState:(UIControlStateNormal)];
    [headerBgView addSubview:notiBtn];
    [notiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.deviceLabel);
        make.left.equalTo(settingBtn.mas_right);
        make.width.height.mas_equalTo(40);
    }];

    CGFloat widths = kGScreenWidth-68*2;
    UIView *view = [[UIView alloc] init];
    view.frame = CGRectMake(68, 120, widths, widths);
    view.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
    view.layer.shadowColor = [UIColor colorWithRed:1/255.0 green:145/255.0 blue:254/255.0 alpha:0.2].CGColor;
    view.layer.shadowOffset = CGSizeMake(0,15);
    view.layer.shadowOpacity = 1;
    view.layer.shadowRadius = 40;
    view.layer.cornerRadius = widths/2;
    [bgScrollview addSubview:view];

    self.deviceImage = [[UIImageView alloc] init];
    self.deviceImage.backgroundColor = UIColor.cyanColor;
    [view addSubview:self.deviceImage];
    [self.deviceImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.offset(0);
        make.width.height.mas_equalTo(170);
    }];

    self.deviceStateLabel = [[UILabel alloc] init];
    self.deviceStateLabel.font = JSS_FONT_4;
    self.deviceStateLabel.textColor = RGB_VALUE(0x6AA9FF);
    self.deviceStateLabel.text = @"已连接";
    self.deviceStateLabel.textAlignment = NSTextAlignmentCenter;
    [view addSubview:self.deviceStateLabel];
    [self.deviceStateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view.mas_top).offset(30);
        make.centerX.offset(0);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(20);
    }];

    self.switchDeviceStateButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.switchDeviceStateButton setTitle:@"运动模式" forState:UIControlStateNormal];
    [self.switchDeviceStateButton setImage:[UIImage imageNamed:@"switch"] forState:UIControlStateNormal];
    [self.switchDeviceStateButton setTitleColor:RGB_VALUE(0x5C6066) forState:UIControlStateNormal];
    [self.switchDeviceStateButton.titleLabel setFont:JSS_FONT_2];
    [self.switchDeviceStateButton layoutButtonWithEdgeInsetsStyle:DVButtonEdgeInsetsStyleRight imageTitleSpace:7];
    [self.switchDeviceStateButton addTarget:self action:@selector(switchDeviceStateButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:self.switchDeviceStateButton];
    [self.switchDeviceStateButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(72);
        make.bottom.offset(-35);
        make.centerX.offset(0);
        make.height.mas_equalTo(17);
    }];

    UIButton *switchDeviceButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [switchDeviceButton addTarget:self action:@selector(switchDeviceButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [bgScrollview addSubview:switchDeviceButton];
    [switchDeviceButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(135);
        make.top.equalTo(view.mas_bottom).offset(-16);
        make.centerX.offset(0);
        make.height.mas_equalTo(32);
    }];
    CAGradientLayer *gl = [CAGradientLayer layer];
    gl.frame = CGRectMake(0, 0, 135, 32);
    gl.startPoint = CGPointMake(0.05, 0.09);
    gl.endPoint = CGPointMake(1, 0.5);
    gl.colors = @[(__bridge id)[UIColor colorWithRed:1/255.0 green:145/255.0 blue:254/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:0/255.0 green:195/255.0 blue:254/255.0 alpha:1.0].CGColor];
    gl.locations = @[@(0), @(1.0f)];
    [switchDeviceButton.layer addSublayer:gl];
    switchDeviceButton.layer.cornerRadius = 16;
    switchDeviceButton.layer.masksToBounds = YES;
    [switchDeviceButton setTitle:@"切换设备" forState:UIControlStateNormal];
    [switchDeviceButton setTitleColor:RGB_VALUE(0xFFFFFF) forState:UIControlStateNormal];
    [switchDeviceButton.titleLabel setFont:JSS_FONT_4];

    UIView *weatherView = [[UIView alloc] init];
    weatherView.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
    weatherView.layer.shadowColor = [UIColor colorWithRed:1/255.0 green:145/255.0 blue:254/255.0 alpha:0.15].CGColor;
    weatherView.layer.shadowOffset = CGSizeMake(0,8);
    weatherView.layer.shadowOpacity = 1;
    weatherView.layer.shadowRadius = 20;
    weatherView.layer.cornerRadius = 90/2;
    [bgScrollview addSubview:weatherView];
    [weatherView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(57+45);
        make.top.equalTo(view.mas_top).offset(-10);
        make.width.height.mas_equalTo(90);
    }];

    self.weatherImage = [[UIImageView alloc] init];
    self.weatherImage.backgroundColor = UIColor.cyanColor;
    [weatherView addSubview:self.weatherImage];
    [self.weatherImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(10);
        make.width.height.mas_equalTo(40);
    }];

    self.weatherLabel = [[UILabel alloc] init];
    self.weatherLabel.font = JSS_FONT_2;
    self.weatherLabel.textColor = RGB_VALUE(0x5C6066);
    self.weatherLabel.text = @"已连接";
    self.weatherLabel.textAlignment = NSTextAlignmentCenter;
    [weatherView addSubview:self.weatherLabel];
    [self.weatherLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.weatherImage.mas_bottom);
        make.left.offset(9);
        make.right.offset(-9);
        make.height.mas_equalTo(17);
    }];
    
    UILabel *consumeLabel = [[UILabel alloc] init];
    consumeLabel.font = JSS_FONT_2;
    consumeLabel.textColor = RGB_VALUE(0x5C6066);
    consumeLabel.text = @"滤棉消耗";
    [bgScrollview addSubview:consumeLabel];
    [consumeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(switchDeviceButton.mas_bottom).offset(51);
        make.left.offset(15);
        make.height.mas_equalTo(17);
        make.width.mas_equalTo(48);
    }];
    
    UIView *progressBGView = [[UIView alloc] init];
    progressBGView.layer.borderWidth = 0.5;
    progressBGView.layer.borderColor = [UIColor colorWithRed:163/255.0 green:172/255.0 blue:192/255.0 alpha:1.0].CGColor;
    progressBGView.layer.backgroundColor = [UIColor colorWithRed:223/255.0 green:231/255.0 blue:244/255.0 alpha:1.0].CGColor;
    progressBGView.layer.cornerRadius = 8;
    [bgScrollview addSubview:progressBGView];
    [progressBGView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(consumeLabel.mas_right).offset(13);
        make.height.equalTo(16);
        make.top.equalTo(consumeLabel.mas_top);
        make.width.mas_equalTo(kGScreenWidth-52-15-48-13);
    }];
    
    self.progressView = [[UIView alloc] init];
    [progressBGView addSubview:self.progressView];
    [self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.height.equalTo(14);
        make.centerY.offset(0);
        make.width.mas_equalTo(165);
    }];
    // gradient
    CAGradientLayer *progressViewgl = [CAGradientLayer layer];
    progressViewgl.frame = CGRectMake(0,0,165,14);
    progressViewgl.startPoint = CGPointMake(0.13, 0);
    progressViewgl.endPoint = CGPointMake(0.13, 0.5);
//    progressViewgl.startPoint = CGPointMake(0.5, 0.01);
//    progressViewgl.endPoint = CGPointMake(0.5, 1);
    progressViewgl.colors = @[(__bridge id)[UIColor colorWithRed:126/255.0 green:216/255.0 blue:246/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:64/255.0 green:145/255.0 blue:255/255.0 alpha:1.0].CGColor];
    progressViewgl.locations = @[@(0), @(1.0f)];
    self.progressView.layer.masksToBounds = YES;
    self.progressView.layer.cornerRadius = 7;
    [self.progressView.layer addSublayer:progressViewgl];
    
    self.spareTimeLabel = [[UILabel alloc] init];
    self.spareTimeLabel.text = @"64h";
    self.spareTimeLabel.font = JSS_FONT_2;
    self.spareTimeLabel.textColor = RGB_VALUE(0xFFFFFF);
    self.spareTimeLabel.textAlignment = NSTextAlignmentCenter;
    [progressBGView addSubview:self.spareTimeLabel];
    [self.spareTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.offset(0);
        make.height.mas_equalTo(17);
        make.width.mas_equalTo(100);
    }];
    
    UIButton *zeroButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [zeroButton setTitle:@"清零" forState:UIControlStateNormal];
    [zeroButton setTitleColor:RGB_VALUE(0x5C6066) forState:UIControlStateNormal];
    [zeroButton.titleLabel setFont:JSS_FONT_2];
    [zeroButton addTarget:self action:@selector(zeroButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [bgScrollview addSubview:zeroButton];
    [zeroButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(progressBGView.mas_right).offset(0);
        make.top.equalTo(consumeLabel.mas_top);
        make.width.mas_equalTo(52);
        make.height.mas_equalTo(17);
    }];
    
    UILabel *notEnoughlabel = [[UILabel alloc] init];
    notEnoughlabel.font = JSS_FONT_2;
    notEnoughlabel.textColor = [UIColor colorWithRed:230/255.0 green:138/255.0 blue:138/255.0 alpha:1.0];
    notEnoughlabel.text = @"";
    [bgScrollview addSubview:notEnoughlabel];
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"滤棉剩余可消耗时间已不足2小时，请及时购买更换"];
    [string addAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:230/255.0 green:138/255.0 blue:138/255.0 alpha:1.000000]} range:NSMakeRange(0, 19)];
    [string addAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:249/255.0 green:69/255.0 blue:74/255.0 alpha:1.000000]} range:NSMakeRange(19, 4)];
//    [string addAttributes:@{NSStrikethroughStyleAttributeName: @(NSUnderlineStyleNone)} range:NSMakeRange(0, 19)];
    [string addAttributes:@{NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)} range:NSMakeRange(19, 4)];
    notEnoughlabel.attributedText = string;
    [notEnoughlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.top.equalTo(consumeLabel.mas_bottom).offset(13);
        make.height.mas_equalTo(17);
        make.right.offset(-15);
    }];
    
    CGFloat fitstWidth = (kGScreenWidth - 45) / 2;
    UIView *breatheView = [[UIView alloc] init];
    breatheView.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
    breatheView.layer.cornerRadius = 10;
    breatheView.layer.shadowColor = [UIColor colorWithRed:93/255.0 green:102/255.0 blue:147/255.0 alpha:0.15].CGColor;
    breatheView.layer.shadowOffset = CGSizeMake(0,2);
    breatheView.layer.shadowOpacity = 1;
    breatheView.layer.shadowRadius = 8;
    [bgScrollview addSubview:breatheView];
    [breatheView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.top.equalTo(notEnoughlabel.mas_bottom).offset(18);
        make.height.mas_equalTo(100);
        make.width.equalTo(fitstWidth);
    }];
    
    UILabel *breathLabel = [[UILabel alloc] init];
    breathLabel.font = JSS_FONT_4;
    breathLabel.textColor = [UIColor colorWithRed:131/255.0 green:146/255.0 blue:167/255.0 alpha:1.0];
    [breatheView addSubview:breathLabel];
    [breathLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.offset(10);
        make.right.offset(-10);
        make.height.mas_equalTo(37);
    }];
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ 次",@"888"]];
    [attrString addAttributes:@{NSForegroundColorAttributeName: RGB_VALUE(0x17E670)} range:NSMakeRange(0, 3)];
    [attrString addAttributes:@{NSFontAttributeName: JSS_FONT(32)} range:NSMakeRange(0, 3)];
    breathLabel.attributedText = attrString;
    
    UILabel *breathSubLabel = [[UILabel alloc] init];
    breathSubLabel.text = @"呼吸里程";
    breathSubLabel.textColor = [UIColor colorWithRed:92/255.0 green:93/255.0 blue:102/255.0 alpha:1.0];
    breathSubLabel.font = JSS_FONT_6;
    [breatheView addSubview:breathSubLabel];
    [breathSubLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.top.equalTo(breathLabel.mas_bottom).offset(13);
        make.width.mas_equalTo(67);
        make.height.mas_equalTo(22);
    }];

    UIImageView *breathSubImg = [[UIImageView alloc] init];
    breathSubImg.image = [UIImage imageNamed:@"lung"];
    [breatheView addSubview:breathSubImg];
    [breathSubImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.bottom.offset(-17);
        make.width.height.mas_equalTo(24);
    }];
    
    UIView *caloriesView = [[UIView alloc] init];
    caloriesView.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
    caloriesView.layer.cornerRadius = 10;
    caloriesView.layer.shadowColor = [UIColor colorWithRed:93/255.0 green:102/255.0 blue:147/255.0 alpha:0.15].CGColor;
    caloriesView.layer.shadowOffset = CGSizeMake(0,2);
    caloriesView.layer.shadowOpacity = 1;
    caloriesView.layer.shadowRadius = 8;
    [bgScrollview addSubview:caloriesView];
    [caloriesView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(breatheView.mas_right).offset(15);
        make.top.equalTo(breatheView.mas_top);
        make.height.mas_equalTo(100);
        make.width.equalTo(breatheView);
        make.right.offset(-15);
    }];
    
    UILabel *caloriesLabel = [[UILabel alloc] init];
    caloriesLabel.font = JSS_FONT_4;
    caloriesLabel.textColor = [UIColor colorWithRed:131/255.0 green:146/255.0 blue:167/255.0 alpha:1.0];
    [caloriesView addSubview:caloriesLabel];
    [caloriesLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.offset(10);
        make.right.offset(-10);
        make.height.mas_equalTo(37);
    }];

    NSMutableAttributedString *attrString1 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ 卡",@"888"]];
    [attrString1 addAttributes:@{NSForegroundColorAttributeName: RGB_VALUE(0xFE6F01)} range:NSMakeRange(0, 3)];
    [attrString1 addAttributes:@{NSFontAttributeName: JSS_FONT(32)} range:NSMakeRange(0, 3)];
    caloriesLabel.attributedText = attrString1;
    
    
    UILabel *caloriesSubLabel = [[UILabel alloc] init];
    caloriesSubLabel.text = @"卡路里值";
    caloriesSubLabel.textColor = [UIColor colorWithRed:92/255.0 green:93/255.0 blue:102/255.0 alpha:1.0];
    caloriesSubLabel.font = JSS_FONT_6;
    [caloriesView addSubview:caloriesSubLabel];
    [caloriesSubLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.top.equalTo(caloriesLabel.mas_bottom).offset(13);
        make.width.mas_equalTo(67);
        make.height.mas_equalTo(22);
    }];
    
    UIImageView *caloriesSubImg = [[UIImageView alloc] init];
    caloriesSubImg.image = [UIImage imageNamed:@"calories"];
    [caloriesView addSubview:caloriesSubImg];
    [caloriesSubImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.bottom.offset(-17);
        make.width.height.mas_equalTo(24);
    }];
    
    UIButton *dataZeroButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [dataZeroButton setTitle:@"数据清零" forState:UIControlStateNormal];
    [dataZeroButton setTitleColor:RGB_VALUE(0x6AA9FF) forState:UIControlStateNormal];
    [dataZeroButton.titleLabel setFont:JSS_FONT_4];
    [dataZeroButton addTarget:self action:@selector(dataZeroButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [bgScrollview addSubview:dataZeroButton];
    [dataZeroButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.equalTo(caloriesView.mas_bottom).offset(20);
        make.width.mas_equalTo(66);
        make.height.mas_equalTo(20);
    }];
    
    CGFloat bottomWidth = (kGScreenWidth - 30 - 16) / 3;
    UIView *breathLightview = [[UIView alloc] init];
    [bgScrollview addSubview:breathLightview];
    breathLightview.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
    breathLightview.layer.cornerRadius = 10;
    breathLightview.layer.shadowColor = [UIColor colorWithRed:93/255.0 green:102/255.0 blue:147/255.0 alpha:0.15].CGColor;
    breathLightview.layer.shadowOffset = CGSizeMake(0,2);
    breathLightview.layer.shadowOpacity = 1;
    breathLightview.layer.shadowRadius = 8;
    [breathLightview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.top.equalTo(dataZeroButton.mas_bottom).offset(15);
        make.height.mas_equalTo(90);
        make.width.mas_equalTo(bottomWidth);
    }];
    
    UISwitch *breathLightSwitch = [[UISwitch alloc] init];
    [breathLightSwitch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
    breathLightSwitch.on = YES;
    breathLightSwitch.onTintColor = RGB_VALUE(0x00C3FE);
    [breathLightview addSubview:breathLightSwitch];
    [breathLightSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(10);
        make.centerX.offset(0);
        make.height.mas_equalTo(39);
        make.width.mas_equalTo(50);
    }];
    
    UILabel *breathLightLabel = [[UILabel alloc] init];
    breathLightLabel.text = @"呼吸灯";
    breathLightLabel.textColor = RGB_VALUE(0x5C5D66);
    breathLightLabel.font = JSS_FONT_4;
    breathLightLabel.textAlignment = NSTextAlignmentCenter;
    [breathLightview addSubview:breathLightLabel];
    [breathLightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.equalTo(breathLightSwitch.mas_bottom).offset(13);
        make.width.mas_equalTo(bottomWidth);
        make.height.mas_equalTo(22);
    }];
    
    UIView *batteryview = [[UIView alloc] init];
    [bgScrollview addSubview:batteryview];
    batteryview.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
    batteryview.layer.cornerRadius = 10;
    batteryview.layer.shadowColor = [UIColor colorWithRed:93/255.0 green:102/255.0 blue:147/255.0 alpha:0.15].CGColor;
    batteryview.layer.shadowOffset = CGSizeMake(0,2);
    batteryview.layer.shadowOpacity = 1;
    batteryview.layer.shadowRadius = 8;
    [batteryview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(breathLightview.mas_right).offset(8);
        make.top.equalTo(dataZeroButton.mas_bottom).offset(15);
        make.height.mas_equalTo(90);
        make.width.mas_equalTo(bottomWidth);
    }];
    
    UIImageView *batteryImg = [[UIImageView alloc] init];
    batteryImg.image = [UIImage imageNamed:@"battery"];
    [batteryview addSubview:batteryImg];
    [batteryImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(10);
        make.centerX.offset(0);
        make.height.mas_equalTo(39);
        make.width.mas_equalTo(39);
    }];
    
    UILabel *batteryLabel = [[UILabel alloc] init];
    batteryLabel.text = @"电量:100%";
    batteryLabel.textColor = RGB_VALUE(0x5C5D66);
    batteryLabel.font = JSS_FONT_4;
    batteryLabel.textAlignment = NSTextAlignmentCenter;
    [batteryview addSubview:batteryLabel];
    [batteryLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.equalTo(batteryImg.mas_bottom).offset(13);
        make.width.mas_equalTo(bottomWidth);
        make.height.mas_equalTo(22);
    }];
    
    UIView *udpateView = [[UIView alloc] init];
    [bgScrollview addSubview:udpateView];
    udpateView.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
    udpateView.layer.cornerRadius = 10;
    udpateView.layer.shadowColor = [UIColor colorWithRed:93/255.0 green:102/255.0 blue:147/255.0 alpha:0.15].CGColor;
    udpateView.layer.shadowOffset = CGSizeMake(0,2);
    udpateView.layer.shadowOpacity = 1;
    udpateView.layer.shadowRadius = 8;
    [udpateView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(batteryview.mas_right).offset(8);
        make.top.equalTo(dataZeroButton.mas_bottom).offset(15);
        make.height.mas_equalTo(90);
        make.width.equalTo(batteryview);
        make.right.offset(-15);
    }];
    
    UIImageView *udpateImg = [[UIImageView alloc] init];
    udpateImg.image = [UIImage imageNamed:@"levelUp"];
    [udpateView addSubview:udpateImg];
    [udpateImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(10);
        make.centerX.offset(0);
        make.height.mas_equalTo(39);
        make.width.mas_equalTo(39);
    }];

    UILabel *udpateLabel = [[UILabel alloc] init];
    udpateLabel.text = @"固件升级";
    udpateLabel.textColor = RGB_VALUE(0x5C5D66);
    udpateLabel.font = JSS_FONT_4;
    udpateLabel.textAlignment = NSTextAlignmentCenter;
    [udpateView addSubview:udpateLabel];
    [udpateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.equalTo(udpateImg.mas_bottom).offset(13);
        make.width.mas_equalTo(bottomWidth);
        make.height.mas_equalTo(22);
    }];
    
    [bgScrollview mas_makeConstraints:^(MASConstraintMaker *make) {
        // 注意点2：
        make.bottom.equalTo(udpateView.mas_bottom).offset(62);
    }];
}

// 设置按钮
- (void)settingBtnClick
{
    MSettingViewController *vc = [[MSettingViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

// 通知按钮
- (void)notiBtnClick
{
    MNotificationViewController *vc = [[MNotificationViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

// 切换模式
- (void)switchDeviceStateButtonClick
{
    
}

// 切换设备
- (void)switchDeviceButtonClick
{
    MDeviceSwitchingViewController *vc = [[MDeviceSwitchingViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

// 清零
- (void)zeroButtonClick
{
    [self.progressView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(0);
    }];
    self.spareTimeLabel.text = @"";
}

// 数据清零
- (void)dataZeroButtonClick
{
    
}

// 数据清零
- (void)switchValueChanged:(UISwitch *)sender
{
    
}
@end
